import 'package:safetymonitor/app/core/core.dart';

/// 简单的通用TabBar
class CustomTabBarWidget extends StatelessWidget {
  const CustomTabBarWidget({required this.tabs, super.key, this.padH, this.padV, this.tabController});

  final List<Widget> tabs;
  final double? padH, padV;
  final TabController? tabController;
  @override
  Widget build(BuildContext context) {
    final List<Widget> map = tabs.map((toElement) {
      return Container(
        constraints: BoxConstraints(minWidth: 86.w),
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(horizontal: padH ?? 55.w, vertical: padV ?? 0),
        child: toElement,
      );
    }).toList();

    return Container(
      alignment: Alignment.center,
      height: 38.w,
      //width: 200.w,
      padding: EdgeInsets.all(2.w),
      margin: EdgeInsets.symmetric(horizontal: 10.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(4.w),
        border: Border.all(color: const Color(0xff2267C0), width: 1.w),
      ),
      child: TabBar(
        controller: tabController,
        isScrollable: true,
        labelPadding: const EdgeInsets.all(0),
        tabAlignment: TabAlignment.center,
        tabs: map,
        dividerColor: Colors.transparent,
        labelStyle: TextStyle(
          fontSize: 16.sp,
          fontWeight: FontWeight.w500,
        ),
        unselectedLabelStyle: TextStyle(
          fontSize: 16.sp,
          fontWeight: FontWeight.w500,
        ),
        labelColor: Colors.white,
        unselectedLabelColor: const Color(0xff2267C0),
        indicator: BoxDecoration(
          color: const Color(0xff2267C0), // 背景颜色
          borderRadius: BorderRadius.circular(4.r), // 圆角
        ),
        indicatorSize: TabBarIndicatorSize.tab,
        // 指示器大小与标签一致
        indicatorWeight: 0.0, // 去掉默认指示器的高度
      ),
    );
  }
}
